package com.myfum.wingplayer.components.decorators
{
	import com.myfum.wingplayer.components.containers.AbstractContainer;
	
	import flash.events.Event;
	
	import mx.controls.SWFLoader;
	
	public class PhotoDecorator extends AbstractDecorator
	{
		public function PhotoDecorator(container:AbstractContainer)
		{
			super(container);
			_loader = new SWFLoader();
		}
		
		private var _loader:SWFLoader;
		
		override public function getReady():void{
			container.data = data;
			container.holder.addChild(_loader);
			_loader.source = container.data.path;
			_loader.maintainAspectRatio = false;
			_loader.addEventListener(Event.COMPLETE, onComplete);
			container.getReady();
		}
		
		override public function dispose():void{
			try{
				_loader.removeEventListener(Event.COMPLETE, onComplete);
				_loader.unloadAndStop();
				_loader = null;
			}catch(e:Error){
			}
			super.dispose();
		}
		
		private function onComplete(evt:Event):void{
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		override public function play():void{
			container.play();
		}
		
		override public function set width(value:Number):void{
			super.width = value;
			_loader.width = width;
		}
		
		override public function set height(value:Number):void{
			super.height = value;
			_loader.height = height;
		}
	}
}